package cn.qyd.lock;

import java.util.concurrent.locks.LockSupport;

/**
 * @author 邱运铎
 * @date 2024-03-21 15:19
 */
public class LockSupportDemo {
    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();

        Thread counterThread = new Thread(() -> {
            for (int i = 0; i < 550; i++) {
                System.out.println(i);
                if (i == 500) {
//                    LockSupport.unpark(mainThread);
                }
            }
        });

        counterThread.start();
        System.out.println("Main Thread was park");
//        LockSupport.parkUntil(System.currentTimeMillis());
//        LockSupport.parkNanos(1);
        LockSupport.park(mainThread);
        System.out.println("Main Thread was unpark");
    }
}
